using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using System.Text;

using Microsoft.SharePoint;
using Microsoft.SharePoint.WebPartPages;
using Microsoft.SharePoint.WebControls;

namespace TweakSP.Web.Application
{
    public partial class TweakSP_GetWebParts : LayoutsPageBase
    {
        private string PageUrl
        {
            get
            {
                return Request["PAGEURL"];
            }
        }

        protected override void OnLoad(EventArgs e)
        {
            string script = string.Empty;

            Response.Clear();
            Response.ContentType = "text/xml";

            script = GetWebParts();

            if (string.IsNullOrEmpty(script))
            {
                Response.Write("Unable to download Web Parts");
            }
            else
            {
                Response.Write(script);
            }

            Response.End();
        }


        private string GetWebParts()
        {
            string partsXml = string.Empty;
            SPWeb web = SPControl.GetContextWeb(Context);

            Microsoft.SharePoint.SoapServer.WebPartPagesWebService svc = new Microsoft.SharePoint.SoapServer.WebPartPagesWebService(web);

            partsXml = svc.GetWebPartProperties2(PageUrl, Storage.Shared, Microsoft.SharePoint.Utilities.SPWebServiceBehavior.Version3).OuterXml;

            return partsXml;
        }

    }
}
